﻿package mortal.game.view.common.guide.stepOperater
{
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.mvc.core.*;

    public class AutoGuideSystemFuncSteper extends AutoGuideStepBase implements IAutoGuideSteper
    {
        private var _effect:SWFPlayer;
        private var _icon:GBitmap;
        private var _timerId:int = -1;

        public function AutoGuideSystemFuncSteper()
        {
            return;
        }// end function

        public function guide(param1:AutoGuideData, param2:Window = null) : void
        {
            if (_working)
            {
                this.stop();
            }
            _data = param1;
            if (param1.needMask)
            {
                super.showMaskByRect(LayerManager.highestLayer, new Rectangle(Global.stage.stageWidth / 2, Global.stage.stageHeight / 2, 1, 1));
            }
            this._effect = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
            this._effect.loadComplete = this.loadEffectCompleteHandler;
            this._effect.timeRate = 4;
            this._effect.load("guideGetSystemFunc.swf", ModelType.NormalSwf, null);
            this._effect.move(Global.stage.stageWidth / 2, Global.stage.stageHeight / 2);
            LayerManager.highestLayer.addChild(this._effect);
            if (param1.guideTypeValue != null && String(param1.guideTypeValue) != "")
            {
                this._icon = UIFactory.gBitmap(param1.guideTypeValue as String, 0, 0, LayerManager.highestLayer);
                this._icon.x = Global.stage.stageWidth / 2 - this._icon.width / 2;
                this._icon.y = Global.stage.stageHeight / 2 - this._icon.height / 2 + 2;
            }
            super.setData(param1, null, this._icon);
            return;
        }// end function

        private function loadEffectCompleteHandler(param1:SWFPlayer) : void
        {
            this._timerId = setTimeout(this.playEnd, 1300);
            return;
        }// end function

        override public function stop(param1:AutoGuideData = null) : void
        {
            super.stop(param1);
            if (this._timerId > 0)
            {
                clearTimeout(this._timerId);
                this._timerId = -1;
            }
            if (this._effect != null)
            {
                this._effect.stop();
                this._effect.dispose(true);
                this._effect = null;
            }
            if (this._icon != null)
            {
                this._icon.dispose(true);
                this._icon = null;
            }
            if (param1 != null)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStepEnd, param1));
            }
            return;
        }// end function

        private function playEnd() : void
        {
            this._timerId = -1;
            this.stop(_data);
            return;
        }// end function

    }
}
